package com.springboot.mongo.service;

import com.springboot.mongo.bean.User;
import com.springboot.mongo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserMongoService{
    @Autowired
    private UserRepository userRepository;

    public List<User> getAllUsers() {
        return userRepository.findAll();
    }

    public User saveUser(User user) {
        return userRepository.save(user);
    }

    public List<User> findByName(String name) {
        return userRepository.findByName(name);
    }
    // 模糊查询 address
    public List<User> findUsersByAddress(String keyword) {
        return userRepository.findByAddressRegex(".*" + keyword + ".*");
    }
}